<template>
  <transition name="custom" @after-leave="handleAfterLeave">
    <div class="toast-box" v-show="show">
      {{ text }}
    </div>
  </transition>
</template>

<script>
export default {
  data() {
    return {
      text: '',
      hidden: null,
      show: false
    }
  },
  methods: {
    handleAfterLeave() {
      this.$destroy(true);
      this.$el.remove()
    }
  }
}
</script>

<style lang="scss" scoped>
.toast-box {
  position: fixed;
  inset: 0;
  z-index: 999;
  padding: 20px;
  width: fit-content;
  height: fit-content;
  flex-shrink: 0;
  border-radius: 12px;
  background: #0000007a;
  color: #ffffff;
  font-size: 16px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.custom-enter-active,
.custom-leave-active {
  -webkit-transition: opacity .2s linear;
  transition: opacity .2s linear
}

.custom-enter,
.custom-leave-to {
  opacity: 0
}
</style>
